/*
 * !! Parameterize WorkerJob so that extensions are unnecessary.
 */
package system;

/**
 * Several MasterJob methods are unused by Workers.
 * The WorkerJob class exists to reduce the class file size. 
 *
 * @author Pete Cappello
 */
public class WorkerJob extends Job
{
    private final GraphMaker workerGraphMaker;
    private final WorkerWriter workerWriter;
    private FileSystem   fileSystem;
    
    public WorkerJob( Job job )
    { 
        super( job );
        workerWriter     = job.getWorkerWriter();
        workerGraphMaker = job.getWorkerGraphMaker();
    }
    
    public FileSystem getFileSystem() { return fileSystem; }
    
    /*
     * @return the number of vertices that were constructed.
     */
    public int makeGraph( Worker worker ) { return workerGraphMaker.makeGraph( worker ); }
    
    public void makeOutputFile( Worker worker ) { workerWriter.write( fileSystem, worker ); }
    
    public int getPartId( Vertex vertex ) { return getPartId( vertex.getVertexId() ); }
    
    public int getPartId( Object vertexId ) { return vertexId.hashCode() % getNumParts(); }
    
    void setFileSystem( FileSystem fileSystem ) { this.fileSystem = fileSystem; }
}
